package com.mofang.ticketing.common.security.component;

import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.util.StrUtil;
import com.mofang.ticketing.common.security.util.SecurityUtil;
import lombok.RequiredArgsConstructor;
import org.springframework.util.PatternMatchUtils;
import java.util.Set;

/**
 * @author LGC
 */
public class PermissionService {
    public boolean hasPerm(String perm) {
        if (StrUtil.isBlank(perm)) {
            return false;
        }
        Set<String> perms = SecurityUtil.getPerms();
        if (CollectionUtil.isEmpty(perms)) {
            return false;
        }
        return perms.stream().anyMatch(item -> PatternMatchUtils.simpleMatch(perm, item));
    }
}
